package com.lgl.scsheader.sameCityManage.controller;

import com.github.pagehelper.PageInfo;
import com.lgl.scsapi.system.model.PageData;
import com.lgl.scsheader.base.controller.BaseController;
import com.lgl.scsheader.sameCityManage.service.SameCityUserService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 同城用户
 */

@RestController
@RequestMapping(value="/sameCityUser")
public class SameCityUserController extends BaseController{
	@Resource(name="sameCityUserService")
	private SameCityUserService sameCityUserService;
	
	//通过条件获取城市集合
	@RequestMapping(value="listAppUser")
	public Object listAppUser() {
		PageData pd = this.getPageData();
		int pageNo = Integer.parseInt(pd.remove("page").toString()),
		pageSize = Integer.parseInt(pd.remove("rows").toString());
		PageInfo userPage = sameCityUserService.listAppUser(pd,pageNo,pageSize);
		return userPage;
	}
	//解冻/冻结用户
	@RequestMapping(value="freezeAppUser")
	public Object freezeAppUser() {
		PageData freezePd = this.getPageData();
		String userId = freezePd.getString("userId"),
		freezeStatus = freezePd.getString("status");
		//如果userId、freezeStatus为空，或freezeStatus不是0和1
		if (!StringUtils.hasText(userId) || !StringUtils.hasText(freezeStatus) ||
				(!"0".equals(freezeStatus) && !"1".equals(freezeStatus))){
			return "1";
		}
		int rows = sameCityUserService.editAppUser(freezePd);
		return rows >= 0 ? "0" : "2";
	}
}